﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HML.Demo
{
    public partial class TabControlPlusStyle2EffectForm : ItemFormTemplate
    {
        public TabControlPlusStyle2EffectForm()
        {
            InitializeComponent();
            this.Load += new System.EventHandler(this.Form_Load);
            this.Shown += new System.EventHandler(this.Form_Shown);
        }

        #region 实现

        public override ItemFormTemplateViewObject AsynchRequestTask(ItemFormTemplateViewObject view)
        {
            System.Threading.Thread.Sleep(300);
            view.ViewData = DemoHelper.GetDescription(AppDomain.CurrentDomain.BaseDirectory + "例子\\控件效果\\选项卡\\TabControlPlusStyle2EffectForm.rtf");
            return view;
        }

        public override void DataBind(ItemFormTemplateViewObject viewObject)
        {
            this.introduceBrowser.Rtf = viewObject.ViewData.ToString();
        }

        public override void ShowView()
        {
            base.ShowView();
        }

        public override void HideView()
        {
            base.HideView();
        }

        public override void CloseView()
        {
            base.CloseView();
        }

        #endregion

        #region 属性面板

        private void Form_Load(object sender, EventArgs e)
        {
            this.controlContainer.SizeChanged += this.ControlContainer_SizeChanged;

            this.demo_control.TabBar.TabItem.ContentOffset = 20;
            this.demo_control.TabBar.TabItem.Size = new Size(80, 80);
            this.demo_control.TabBar.TabItem.RoundSize = new RoundCorner(0);
            this.demo_control.TabBar.TabItem.RoundQuality = false;
            this.demo_control.StyleAppearance.TabBar.TabItem.Normal.BackColor = Color.Transparent;
            this.demo_control.StyleAppearance.TabBar.TabItem.Enter.BackColor = Color.Transparent;
            this.demo_control.StyleAppearance.TabBar.TabItem.Selected.BackColor = Color.Transparent;
            this.demo_control.TabItemDrawBackgroundBefore += this.Demo_control_TabItemDrawBackgroundBefore;

            this.demo_tabPagePlus1.TabItem.Icon.Image = global::HML.Demo.Properties.Resources.控件效果_TabControlPlus_Style2_Ico1;
            this.demo_tabPagePlus2.TabItem.Icon.Image = global::HML.Demo.Properties.Resources.控件效果_TabControlPlus_Style2_Ico2;
            this.demo_tabPagePlus3.TabItem.Icon.Image = global::HML.Demo.Properties.Resources.控件效果_TabControlPlus_Style2_Ico3;
            this.demo_tabPagePlus4.TabItem.Icon.Image = global::HML.Demo.Properties.Resources.控件效果_TabControlPlus_Style2_Ico4;
            this.demo_tabPagePlus5.TabItem.Icon.Image = global::HML.Demo.Properties.Resources.控件效果_TabControlPlus_Style2_Ico5;
        }

        private void Form_Shown(object sender, EventArgs e)
        {
            this.splitContainer.SplitterDistance = Math.Max(this.splitContainer.Width / 4, this.splitContainer.Width - MainForm.GlobalSplitWidth);
            this.splitContainer.SplitterMoved += this.SplitContainer_SplitterMoved;

            MainForm.LoadAssistTabControl(this.assistTabControl);
        }

        private void SplitContainer_SplitterMoved(object sender, SplitterEventArgs e)
        {
            SplitContainer control = (SplitContainer)sender;
            MainForm.GlobalSplitWidth = this.splitContainer.Width - control.SplitterDistance;
        }

        private void ControlContainer_SizeChanged(object sender, EventArgs e)
        {
            Panel control = (Panel)sender;
            this.demo_control.Location = new Point((control.Width - this.demo_control.Width) / 2, (control.Height - this.demo_control.Height) / 2);
        }

        private void Demo_control_TabItemDrawBackgroundBefore(object sender, TabControlPlusTabItemDrawBackgroundBeforeEventArgs e)
        {
            TabControlPlus tabControl = (TabControlPlus)e.TabPage.Parent;
            if (e.TabPage != null && (e.TabPage.IsMouseEnter || tabControl.TabPages[tabControl.SelectedIndex] == e.TabPage))
            {
                Rectangle back_rect = new Rectangle((int)e.Bounds_P.X, (int)e.Bounds_P.Y, (int)e.Bounds_P.Width, (int)e.Bounds_P.Height);
                LinearGradientBrush line_back_lgb = new LinearGradientBrush(back_rect, tabControl.StyleAppearance.TabBar.TabItem.Normal.BackColor, tabControl.StyleAppearance.TabBar.TabItem.Selected.BackColor, LinearGradientMode.Vertical);
                LinearGradientBrush line_lgb = new LinearGradientBrush(new PointF(e.Bounds_P.X, e.Bounds_P.Y), new PointF(e.Bounds_P.X, e.Bounds_P.Bottom), tabControl.StyleAppearance.TabBar.TabItem.Normal.BackColor, tabControl.StyleAppearance.TabBar.TabItem.Selected.BackColor);
                Pen line_pen = new Pen(line_lgb, 1);

                e.Graphics.FillRectangle(line_back_lgb, back_rect);
                e.Graphics.DrawLine(line_pen, new PointF(e.Bounds_P.X, e.Bounds_P.Y), new PointF(e.Bounds_P.X, e.Bounds_P.Bottom));
                e.Graphics.DrawLine(line_pen, new PointF(e.Bounds_P.Right - 1, e.Bounds_P.Y), new PointF(e.Bounds_P.Right - 1, e.Bounds_P.Bottom));

                line_lgb.Dispose();
                line_back_lgb.Dispose();
                line_pen.Dispose();

            }
            if (e.TabPage.TabItem.Icon.Image != null)
            {
                int padding = (int)(Math.Ceiling(10 * this.demo_control.ScaleDpi));
                int ico_whdth = (int)(Math.Ceiling(35 * this.demo_control.ScaleDpi));
                RectangleF ico_rect = new RectangleF(e.Bounds_P.X + (e.Bounds_P.Width - ico_whdth) / 2, e.Bounds_P.Y + padding, ico_whdth, ico_whdth);
                e.Graphics.DrawImage(e.TabPage.TabItem.Icon.Image, ico_rect, new RectangleF(0, 0, e.TabPage.TabItem.Icon.Image.Width, e.TabPage.TabItem.Icon.Image.Height), GraphicsUnit.Pixel);
            }
            e.Cancel = true;
        }

        #endregion

    }
}
